package com.oauth2demo.doman;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.util.Collection;

/**
 * <h3>oauth2Demo</h3>
 * <p>用户表</p>
 *
 * @author gdw
 * @since 2024-07-04 10:40:44
 */
@Data
public class SecurityUser implements UserDetails {
    private SysUser user;

    public SecurityUser() {
    }

    public SecurityUser(SysUser user) {
        this.user=user;
    }

    /**
     * 权限
     * @return
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getUsername() {
        return user.getUserName();
    }
    @Override
    public String getPassword() {
        return user.getPassword();
    }

    /**
     * 账户是否未过期,过期无法验证
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 指定用户是否解锁,锁定的用户无法进行身份验证
     *
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 指示是否已过期的用户的凭据(密码),过期的凭据防止认证
     *
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return user.getEnabled();
    }
}
